﻿<Page
    x:Name="PageRoot"
    x:Class="IntegrationExampleLauncher.InternalFileListingPickerPage"
    DataContext="{Binding DefaultViewModel, RelativeSource={RelativeSource Self}}"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:IntegrationExampleLauncher"
    xmlns:common="using:IntegrationExampleLauncher.Common"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    d:ExtensionType="FileOpenPicker">

    <Page.Resources>
        <CollectionViewSource x:Name="FilesViewSource" Source="{Binding Files}"/>
        <DataTemplate x:Key="ExampleFileTemplate">
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto"/>
                    <ColumnDefinition Width="*"/>
                </Grid.ColumnDefinitions>
                <Grid Grid.Column="0" Background="{ThemeResource ListViewItemPlaceholderBackgroundThemeBrush}" Margin="20">
                    <Image Source="{Binding Image}" 
                                       Width="80" Height="80"
                                       HorizontalAlignment="Center" VerticalAlignment="Center" 
                                       Stretch="Uniform"/>
                </Grid>
                <StackPanel Grid.Column="1" Width="200" Margin="0,20,20,20">
                    <TextBlock Text="{Binding Title}" TextWrapping="NoWrap" 
                               Style="{StaticResource BodyTextBlockStyle}"/>
                    <TextBlock Text="{Binding Description}" MaxHeight="40" 
                               Foreground="{ThemeResource ApplicationSecondaryForegroundThemeBrush}" 
                               Style="{StaticResource BodyTextBlockStyle}"/>
                </StackPanel>
            </Grid>
        </DataTemplate>
    </Page.Resources>

    <!--
        This grid acts as a root panel for the page that defines two rows:
        * Row 0 contains the command area
        * Row 1 contains the rest of the page layout
    -->
    <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
        <Grid.ChildrenTransitions>
            <TransitionCollection>
                <EntranceThemeTransition/>
            </TransitionCollection>
        </Grid.ChildrenTransitions>

        <Grid.RowDefinitions>
            <RowDefinition Height="80"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <!-- Horizontal scrolling grid of files fills the remainder -->
        <GridView
            x:Name="FileGridView"
            AutomationProperties.AutomationId="FileGridView"
            AutomationProperties.Name="Files"
            Grid.Row="0" Grid.RowSpan="2"
            ItemsSource="{Binding Source={StaticResource FilesViewSource}}"
            ItemTemplate="{StaticResource ExampleFileTemplate}"
            SelectionMode="Multiple"
            SelectionChanged="FileGridView_SelectionChanged"
            Padding="116,76,116,20" />

        <!-- A vertical scrolling list is used when the window is less than 500 px wide -->
        <ListView
            x:Name="FileListView"
            AutomationProperties.AutomationId="fileListView"
            AutomationProperties.Name="Files"
            Grid.Row="0" Grid.RowSpan="2"
            ItemsSource="{Binding Source={StaticResource FilesViewSource}}"
            ItemTemplate="{StaticResource ExampleFileTemplate}"
            SelectionMode="Multiple"
            SelectionChanged="FileGridView_SelectionChanged"
            Margin="10,0,0,0"
            Padding="0,0,0,60"
            Visibility="Collapsed" />

        <!-- Command area -->
        <StackPanel Grid.Row="0" x:Name="CommandPanel" Orientation="Horizontal" Margin="120,20,120,30">
            <Button
                AutomationProperties.AutomationId="GoUpButton"
                AutomationProperties.Name="Go Up"
                Click="GoUpButton_Click"
                IsEnabled="{Binding CanGoUp}"
                Margin="-3,-3,35,0"
                Style="{StaticResource TextBlockButtonStyle}"
                Foreground="{ThemeResource ApplicationSecondaryForegroundThemeBrush}">
                <TextBlock Text="Go Up" Margin="3,-7,3,10" Style="{StaticResource SubheaderTextBlockStyle}" TextWrapping="NoWrap" />
            </Button>
        </StackPanel>

        <VisualStateManager.VisualStateGroups>
            <!-- Visual states reflect the application's view state -->
            <VisualStateGroup x:Name="ViewStates">
                <VisualState x:Name="HorizontalView" />
                <!-- Switch to vertical scrolling when the window size is less than 500px-->
                <VisualState x:Name="VerticalView">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="FileGridView" Storyboard.TargetProperty="Visibility">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="Collapsed"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="FileListView" Storyboard.TargetProperty="Visibility">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="Visible"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="CommandPanel" Storyboard.TargetProperty="Margin">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="20,20,20,30"/>
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>
            </VisualStateGroup>
        </VisualStateManager.VisualStateGroups>
    </Grid>
</Page>
